
# 生成测试报告
"""
回顾 ：
unittest.TestLoader().discover(path,patten)
        path : 读取测试用例的路径
        patten : 匹配的模式

测试套件 ：
    1. 冒烟测试用例 :[P0]
    2. 回归测试用例套件 : [P0,P1]
"""


import unittest
from HTMLTestRunner import HTMLTestRunner
from api.base import Base
from setting import TEST_REPORT,suite,LOG_FILE,LOG_LEVEL
from utils.basic_utils import select_case_level, get_log
from loguru import logger

if __name__ == '__main__':

    base = Base()
    base.login()

    # 定义日志文件路径
    log_path = get_log(LOG_FILE)
    # 添加日志
    logger.add(log_path,level=LOG_LEVEL,rotation='5mb')

    # 创建冒烟套件
    tests = select_case_level(suite)
    suite = unittest.TestSuite()
    suite.addTests(tests)
    # smoke_suite = unittest.TestLoader().discover('cases','test*flow.py')
    print(suite)

    with open(TEST_REPORT,'wb') as f:
        runner = HTMLTestRunner(f,title='litemall测试报告',description='v1版本测试报告')
        runner.run(suite)